package com.caidanxiaoyuan.service.impl;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.caidanxiaoyuan.mapper.BaseMapper;
import com.caidanxiaoyuan.model.BaseModel;
import com.caidanxiaoyuan.service.BaseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


/**
 * 
 * @author zhaoyulong
 *
 * @param <T>
 */
@Service
public abstract class BaseServiceImpl<T extends BaseModel> implements BaseService<T>{
	
	@Autowired
	BaseMapper<T> baseMapper;
	
	@Autowired  
	private HttpSession session;  

	public int deleteByPrimaryKey(String id) {
		return baseMapper.deleteByPrimaryKey(id);
	}
	
	public int deleteByPrimaryKey(Integer id) {
		return baseMapper.deleteByPrimaryKey(id);
	}

	public int insert(T record) {
		return baseMapper.insert(record);
	}

	public T selectByPrimaryKey(String id) {
		return baseMapper.selectByPrimaryKey(id);
	}

	public T selectByPrimaryKey(Integer id) {
		return baseMapper.selectByPrimaryKey(id);
	}
	
	public List<T> selectByUs(T t) {
		return baseMapper.selectByUs(t);
	}
	
	
	public List<T> selectAll(Page<T> page) {
		
		PageHelper.startPage(page.getPageNum()==0?1:page.getPageNum(), page.getPageSize()==0?10:page.getPageSize());
		
		List<T> list = baseMapper.selectAll();
		
		return list;
	}
	
	public List<T> selectAll(Page<T> page,T t) {
		
		PageHelper.startPage(page.getPageNum()==0?1:page.getPageNum(), page.getPageSize()==0?10:page.getPageSize());
		
		List<T> list = baseMapper.selectAllByWhere(t);
		
		return list;
	}

	
	public int updateByPrimaryKey(T record) {
		return baseMapper.updateByPrimaryKey(record);
	}
	
}
